﻿@using BlogEngine.Core

@helper CurrentClass(string pg)
{
    var current = "class=\"content-box-selected\"";
    if (Request.Path.ToLower().Contains(pg.ToLower()))
    {
        __razor_helper_writer.Write(current);
    }
}

@helper InstalledThemes()
{
    var path = Server.MapPath(string.Format("{0}themes/", Utils.ApplicationRelativeWebRoot));
    var loaderSrc = Path.Combine(Utils.ApplicationRelativeWebRoot, "pics/ajax-loader.gif");

    var currTheme = BlogEngine.Core.Packaging.PackageManager.GetCurrentTheme(BlogSettings.Instance.Theme);  
    var currMobileTheme = BlogEngine.Core.Packaging.PackageManager.GetCurrentTheme(BlogSettings.Instance.MobileTheme);
    

    <div class="installed-themes">
        <ul class="gallery">
            <li>
                <div class="Theme">
                    <div class="pkg-img">
                        <img src="@currTheme.IconUrl" class="thumbnail" alt="current theme" />
                    </div>
                    <div class="ext-prop">
                        <h2>@Resources.labels.currentTheme: @BlogSettings.Instance.Theme @currTheme.Version</h2>
                        <div class="properties">
                            @if(!string.IsNullOrEmpty(currTheme.Description)){
                            <p>@currTheme.Description</p>
                            }
                            <p>@Resources.labels.author: @currTheme.Authors</p>
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <div class="Theme">
                    <div class="pkg-img">
                        <img src="@currMobileTheme.IconUrl" class="thumbnail" alt="mobile theme" />
                    </div>
                    <div class="ext-prop">
                        <h2>@Resources.labels.mobileTheme: @BlogSettings.Instance.MobileTheme @currMobileTheme.Version</h2>
                        <div class="properties">
                            @if (!string.IsNullOrEmpty(currMobileTheme.Description)){
                            <p>@currMobileTheme.Description</p>
                            }
                            <p>@Resources.labels.author: @currMobileTheme.Authors</p>
                        </div>
                    </div>
                </div>
            </li>
        </ul>
    </div>
   
    <h2>@Resources.labels.available</h2>
    <div class="available-themes">
        <ul class="gallery">
        @foreach (var theme in Blog.CurrentInstance.InstalledThemes)
        {
            if (theme.Id == BlogSettings.Instance.Theme || theme.Id == BlogSettings.Instance.MobileTheme) { continue; }
        <li id="@theme.Id">
            <div class="Theme">
                <div class="pkg-img">
                    <img src="@theme.IconUrl" class="thumbnail" alt="theme" />
                </div>
                <div class="ext-prop">
                    @if (!string.IsNullOrWhiteSpace(theme.Version))
                    {
                    <h2>@theme.Id @theme.Version</h2> 
                    }
                    else
                    {
                    <h2>@theme.Id</h2>
                    }
                    <div class="properties">
                        @if (!string.IsNullOrWhiteSpace(theme.Description))
                        {
                        <p>@theme.Description</p>   
                        }
                        @if (!string.IsNullOrWhiteSpace(theme.Tags))
                        {
                        <p>Tags: @theme.Tags</p>   
                        }
                        @if (!string.IsNullOrWhiteSpace(theme.Authors))
                        {
                         <p>@Resources.labels.author: @theme.Authors</p>   
                        }
                        else
                        {
                        <p>@Resources.labels.author: unknown</p>
                        }
                        <p>
                            <a href="" onclick="SetCurrentTheme('@theme.Id','false'); return false;">@Resources.labels.setAsCurrentTheme</a>&nbsp;|
                            <a href="" onclick="SetCurrentTheme('@theme.Id','true'); return false;">@Resources.labels.setAsMobileTheme</a>&nbsp;|
                            <a href="" onclick="window.open('@Path.Combine(Blog.CurrentInstance.RelativeWebRoot, "?theme=")@theme.Id','themepreview','width=1000,height=700,scrollbars=yes,resizable=yes'); return false">@Resources.labels.preview</a>
                        </p>
                        @if (Blog.CurrentInstance.IsPrimary) {
                            <p>
                                <a href="" class="deleteAction" onclick="UninstallPackage('@theme.Id'); return false;">@Resources.labels.delete</a>
                                <img class="loader2" src="@loaderSrc" alt="loader" />
                            </p>
                        }
                    </div>
                </div>
            </div>
        </li>
        }
        </ul>
    </div>
}
